/**
 * Copyright 2016 JustWayward Team
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ecy.quadratic.api;

import com.ecy.quadratic.beans.BaseResponseBean;
import com.ecy.quadratic.beans.ComicDetailResponseBean;
import com.ecy.quadratic.beans.ComicRecommendResponseBean;
import com.ecy.quadratic.beans.ComicResponseBean;
import com.ecy.quadratic.beans.ComicSectionDetailResponseBean;
import com.ecy.quadratic.beans.CommunityCommentListResponseBean;
import com.ecy.quadratic.beans.CommunityListResponseBean;
import com.ecy.quadratic.beans.NovelResponseBean;
import com.ecy.quadratic.beans.VideoResponseBean;
import com.ecy.quadratic.config.ServerConfig;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;

/**
 * https://github.com/JustWayward/BookReader
 *
 * @author yuyh.
 * @date 2016/8/3.
 */
public class ComicApi {

    public static ComicApi instance;

    private ComicApiService service;

    public ComicApi(OkHttpClient okHttpClient) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(ServerConfig.BASE_SERVER_URL)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // 添加Rx适配器
                .addConverterFactory(GsonConverterFactory.create()) // 添加Gson转换器
                .client(okHttpClient)
                .build();
        service = retrofit.create(ComicApiService.class);
    }

    public static ComicApi getInstance(OkHttpClient okHttpClient) {
        if (instance == null)
            instance = new ComicApi(okHttpClient);
        return instance;
    }

    public Observable<ComicRecommendResponseBean> getComicRecommend(String page) {
        return service.getComicRecommend(page);
    }

    public Observable<NovelResponseBean> getNovelRecommend(String page) {
        return service.getNovelRecommend(page);
    }

    public Observable<ComicResponseBean> getComicList(String page, String classify) {
        return service.getComicList(page, classify);
    }

    public Observable<CommunityListResponseBean> getLastCommunityList(String page) {
        return service.getLastCommunityList(page);
    }

    public Observable<CommunityListResponseBean> getHotCommunityList(String page) {
        return service.getHotCommunityList(page);
    }

    public Observable<CommunityCommentListResponseBean> getCommunityCommentList(String commentId, String page) {
        return service.getCommunityCommentList(commentId, page);
    }

    public Observable<BaseResponseBean> postCommunityComment(String communityId, String userid, String user, String content) {
        return service.postCommunityComment(communityId, userid, user, content);
    }

    public Observable<CommunityCommentListResponseBean> getComicCommentList(String commentId, String page) {
        return service.getComicCommentList(commentId, page);
    }

    public Observable<BaseResponseBean> postComicyComment(String communityId, String userid, String user, String content) {
        return service.postComicComment(communityId, userid, user, content);
    }

    public Observable<CommunityCommentListResponseBean> getBookCommentList(String commentId, String page) {
        return service.getBookCommentList(commentId, page);
    }

    public Observable<BaseResponseBean> postBookComment(String communityId, String userid, String user, String content) {
        return service.postBookComment(communityId, userid, user, content);
    }

    public Observable<BaseResponseBean> postCommunityLike(String communityId) {
        return service.postLike(communityId, "", "", "");
    }

    public Observable<ComicDetailResponseBean> getComicDetail(String id) {
        return service.getComicDetail(id);
    }

    public Observable<VideoResponseBean> getVideoList(String page) {
        return service.getVideoList(page);
    }

    public Observable<ComicSectionDetailResponseBean> getComicChapterImgs(String id) {
        return service.getFuComicImgs(id, "ar", "1.4.0.0", "866401021740231", "", "xiaomi", "FuCiYuan", "false", "");
    }
}
